package com.example.demo.controller;


import com.example.demo.Service.LibrarianService;
import com.example.demo.mapper.LibrarianMapper;
import com.example.demo.model.Librarian;
import com.example.demo.util.JsonData;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/librarian")
public class LibrarianController {


    @Autowired
    LibrarianService librarianService;

    @PostMapping("/add")
    public JsonData addLibrarian(@RequestBody Librarian newLibrarian){
        Integer result = librarianService.addLibrarian(newLibrarian);
        if(result != null){
            
            return JsonData.buildSuccess(result);
        }else {
            return JsonData.buildError("插入失败");
        }
    }

    @GetMapping("/list")
    public JsonData getLibrarianList(){
        List<Librarian> result = librarianService.getLibrarianList();
        if(result != null){
            return JsonData.buildSuccess(result);
        }else {
            return JsonData.buildError("查询失败");
        }
    }

    @PostMapping("/modify")
    public JsonData modifyLibrarianInfo(@RequestBody Librarian info){
        Integer result = librarianService.modifyLibrarianInfo(info);
        if(result != 0){
            return JsonData.buildSuccess(result);
        }else {
            return JsonData.buildError("更新失败");
        }
    }

    @PostMapping("/delete")
    public JsonData deleteLibrarian(@RequestBody Map<String, Integer> user){
        Integer result = librarianService.deleteLibrarian(user.get("employee_id"));
        if(result != 0){
            return JsonData.buildSuccess(result);
        }else {
            return JsonData.buildError("删除失败");
        }
    }

}
